﻿using System;
using System.Text;

using Yawf.Core.Logs;
using Yawf.Security.Entities;
using Yawf.Web.Managers.Entities;
using Yawf.Web.Utils;

namespace Yawf.Web.Managers {
	public class EchoViewManager :IModelViewerManager{
		/// <summary>
		/// This MOdelViewManager just Echos the content of the View to output
		/// stream
		/// </summary>
		/// <param name="requestWrapper">RequestWrapper </param>
		/// <param name="responseWrapper">ResponseWrapper</param>
		/// <param name="view">View object</param>
		/// <param name="user">Current User</param>
		public void ProcessView(RequestWrapper requestWrapper,ResponseWrapper responseWrapper,View view,IUser user) {
			Byte[] contentBytes;
			Encoding enc = Encoding.UTF8;

			try {
				enc = Encoding.GetEncoding(view.Encoding);
				contentBytes = enc.GetBytes(view.Content);
				responseWrapper.OutputStream.Write(contentBytes,0,contentBytes.Length);
			} catch (Exception e) {
				Log.ExceptionMessage(this.GetType(),"Enconding " + view.Encoding + " not found",e);
			}
		}							// ProcessView
	}
}
